﻿
// **************************************************************************
//    Class Created by Mick Doherty (Dotnetrix) Feb 2010
//    http://dotnetrix.co.uk/
//
//    ...for GlassUI (an AeroGlass UI Library)
//    http://glassui.codeplex.com/
// **************************************************************************

using System;
using System.Drawing;
using System.Runtime.InteropServices;

namespace GlassUI
{
    internal sealed partial class NativeMethods
    {
        internal sealed class USER32
        {
            private USER32() { }

            #region Method Imports

            [DllImport("user32.dll", SetLastError = true, CharSet=CharSet.Ansi)]
            public static extern IntPtr SendMessage(IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam);

            [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
            public static extern IntPtr SendMessage(IntPtr hWnd, EditControlMessage Msg, IntPtr wParam, IntPtr lParam);

            [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
            public static extern IntPtr SendMessage(IntPtr hWnd, COMCTL32.HeaderControlMessage Msg, IntPtr wParam, IntPtr lParam);

            [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
            public static extern IntPtr SendMessage(IntPtr hWnd, COMCTL32.ListViewMessage Msg, IntPtr wParam, IntPtr lParam);

            [DllImport("user32.dll", SetLastError = true)]
            [return: MarshalAs(UnmanagedType.Bool)]
            public static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);

            [DllImport("user32.dll", SetLastError = true)]
            public static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, DCXFLAGS flags);

            [DllImport("user32.dll", SetLastError = true)]
            public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

            [DllImport("user32.dll", SetLastError = true)]
            [return: MarshalAs(UnmanagedType.Bool)]
            public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SETWINDOWPOS uFlags);

            [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError=true)]
            public static extern int RealGetWindowClass(IntPtr hwnd, System.Text.StringBuilder pszType, int cchType);

            [DllImport("User32.dll", SetLastError=true)]
            public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, ref Point lpPoints, int cPoints);

            #endregion

            #region Structures

            [StructLayout(LayoutKind.Sequential)]
            public struct RECT
            {
                public int left;
                public int top;
                public int right;
                public int bottom;
                public RECT(Rectangle rc)
                {
                    left = rc.Left;
                    top = rc.Top;
                    right = rc.Right;
                    bottom = rc.Bottom;
                }
                public Rectangle ToRectangle()
                {
                    return Rectangle.FromLTRB(left, top, right, bottom);
                }
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct NCCALCSIZE_PARAMS
            {
                public RECT rgrc0, rgrc1, rgrc2;
                public WINDOWPOS lppos;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct WINDOWPOS
            {
                public IntPtr hWnd, hWndInsertAfter;
                public int x, y, cx, cy, flags;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct WINDOWINFO
            {
                public int cbSize;
                public RECT rcWindow, rcClient;
                public int dwStyle, dwExStyle, dwWindowStatus, cxWindowBorders, cyWindowBorders;
                public IntPtr atomWindowType;
                public short wCreatorVersion;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct TRACKMOUSEEVENT
            {
                public int cbSize;
                public TRACKMOUSEEVENTFLAGS dwFlags;
                public IntPtr hwndTrack;
                public int dwHoverTime;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct CREATESTRUCT
            {
                public IntPtr lpCreateParams, hInstance, hMenu, hwndParent;
                public int cy, cx, y, x, style;
                public IntPtr lpszName, lpszClass;
                public int dwExStyle;
            }

            [StructLayout(LayoutKind.Sequential)]
            public struct PAINTSTRUCT
            {
                public IntPtr hdc;
                [MarshalAs(UnmanagedType.Bool)]
                public bool fErase;
                public RECT rcPaint;
                [MarshalAs(UnmanagedType.Bool)]
                public bool fRestore;
                [MarshalAs(UnmanagedType.Bool)]
                public bool fIncUpdate;
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
                public byte[] rgbReserved;
            }

            #endregion

            #region Enumerations

            public enum WindowMessage
            {
                WM_NULL = 0X0,
                WM_CREATE = 0X1,
                WM_DESTROY = 0X2,
                WM_MOVE = 0X3,
                WM_SIZE = 0X5,

                WM_ACTIVATE = 0X6,

                WM_SETFOCUS = 0X7,
                WM_KILLFOCUS = 0X8,
                WM_ENABLE = 0XA,
                WM_SETREDRAW = 0XB,
                WM_SETTEXT = 0XC,
                WM_GETTEXT = 0XD,
                WM_GETTEXTLENGTH = 0XE,
                WM_PAINT = 0XF,
                WM_CLOSE = 0X10,

                WM_QUERYENDSESSION = 0X11,
                WM_QUIT = 0X12,
                WM_QUERYOPEN = 0X13,
                WM_ERASEBKGND = 0X14,
                WM_SYSCOLORCHANGE = 0X15,
                WM_ENDSESSION = 0X16,

                WM_SHOWWINDOW = 0X18,
                WM_WININICHANGE = 0X1A,
                WM_SETTINGCHANGE = WM_WININICHANGE,

                WM_DEVMODECHANGE = 0X1B,
                WM_ACTIVATEAPP = 0X1C,
                WM_FONTCHANGE = 0X1D,
                WM_TIMECHANGE = 0X1E,
                WM_CANCELMODE = 0X1F,
                WM_SETCURSOR = 0X20,
                WM_MOUSEACTIVATE = 0X21,
                WM_CHILDACTIVATE = 0X22,
                WM_QUEUESYNC = 0X23,

                WM_GETMINMAXINFO = 0X24,

                WM_PAINTICON = 0X26,
                WM_ICONERASEBKGND = 0X27,
                WM_NEXTDLGCTL = 0X28,
                WM_SPOOLERSTATUS = 0X2A,
                WM_DRAWITEM = 0X2B,
                WM_MEASUREITEM = 0X2C,
                WM_DELETEITEM = 0X2D,
                WM_VKEYTOITEM = 0X2E,
                WM_CHARTOITEM = 0X2F,
                WM_SETFONT = 0X30,
                WM_GETFONT = 0X31,
                WM_SETHOTKEY = 0X32,
                WM_GETHOTKEY = 0X33,
                WM_QUERYDRAGICON = 0X37,
                WM_COMPAREITEM = 0X39,

                WM_GETOBJECT = 0X3D,

                WM_COMPACTING = 0X41,

                //** No Longer supported *
                WM_COMMNOTIFY = 0X44,
                //************************

                WM_WINDOWPOSCHANGING = 0X46,
                WM_WINDOWPOSCHANGED = 0X47,

                WM_COPYDATA = 0X4A,
                WM_CANCELJOURNAL = 0X4B,

                WM_NOTIFY = 0X4E,
                WM_INPUTLANGCHANGEREQUEST = 0X50,
                WM_INPUTLANGCHANGE = 0X51,
                WM_TCARD = 0X52,
                WM_HELP = 0X53,
                WM_USERCHANGED = 0X54,
                WM_NOTIFYFORMAT = 0X55,

                WM_CONTEXTMENU = 0X7B,
                WM_STYLECHANGING = 0X7C,
                WM_STYLECHANGED = 0X7D,
                WM_DISPLAYCHANGE = 0X7E,
                WM_GETICON = 0X7F,
                WM_SETICON = 0X80,

                WM_NCCREATE = 0X81,
                WM_NCDESTROY = 0X82,
                WM_NCCALCSIZE = 0X83,
                WM_NCHITTEST = 0X84,
                WM_NCPAINT = 0X85,
                WM_NCACTIVATE = 0X86,
                WM_GETDLGCODE = 0X87,

                WM_SYNCPAINT = 0X88,

                WM_NCMOUSEMOVE = 0XA0,
                WM_NCLBUTTONDOWN = 0XA1,
                WM_NCLBUTTONUP = 0XA2,
                WM_NCLBUTTONDBLCLK = 0XA3,
                WM_NCRBUTTONDOWN = 0XA4,
                WM_NCRBUTTONUP = 0XA5,
                WM_NCRBUTTONDBLCLK = 0XA6,
                WM_NCMBUTTONDOWN = 0XA7,
                WM_NCMBUTTONUP = 0XA8,
                WM_NCMBUTTONDBLCLK = 0XA9,

                WM_NCXBUTTONDOWN = 0XAB,
                WM_NCXBUTTONUP = 0XAC,
                WM_NCXBUTTONDBLCLK = 0XAD,

                WM_INPUT = 0XFF,

                WM_KEYFIRST = 0X100,
                WM_KEYDOWN = 0X100,
                WM_KEYUP = 0X101,
                WM_CHAR = 0X102,
                WM_DEADCHAR = 0X103,
                WM_SYSKEYDOWN = 0X104,
                WM_SYSKEYUP = 0X105,
                WM_SYSCHAR = 0X106,
                WM_SYSDEADCHAR = 0X107,

                WM_UNICHAR = 0X109,
                WM_KEYLAST_XP = 0X109,
                WM_KEYLAST = 0X108,

                WM_IME_STARTCOMPOSITION = 0X10D,
                WM_IME_ENDCOMPOSITION = 0X10E,
                WM_IME_COMPOSITION = 0X10F,
                WM_IME_KEYLAST = 0X10F,

                WM_INITDIALOG = 0X110,
                WM_COMMAND = 0X111,
                WM_SYSCOMMAND = 0X112,
                WM_TIMER = 0X113,
                WM_HSCROLL = 0X114,
                WM_VSCROLL = 0X115,
                WM_INITMENU = 0X116,
                WM_INITMENUPOPUP = 0X117,

                //***** UNDOCUMENTED *****
                WM_SYSTIMER = 0X118,
                //************************

                WM_GESTURE = 0x0119,
                WM_GESTURENOTIFY = 0x011A,

                WM_MENUSELECT = 0X11F,
                WM_MENUCHAR = 0X120,
                WM_ENTERIDLE = 0X121,

                WM_MENURBUTTONUP = 0X122,
                WM_MENUDRAG = 0X123,
                WM_MENUGETOBJECT = 0X124,
                WM_UNINITMENUPOPUP = 0X125,
                WM_MENUCOMMAND = 0X126,

                WM_CHANGEUISTATE = 0X127,
                WM_UPDATEUISTATE = 0X128,
                WM_QUERYUISTATE = 0X129,

                WM_CTLCOLORMSGBOX = 0X132,
                WM_CTLCOLOREDIT = 0X133,
                WM_CTLCOLORLISTBOX = 0X134,
                WM_CTLCOLORBTN = 0X135,
                WM_CTLCOLORDLG = 0X136,
                WM_CTLCOLORSCROLLBAR = 0X137,
                WM_CTLCOLORSTATIC = 0X138,

                WM_MOUSEFIRST = 0X200,
                WM_MOUSEMOVE = 0X200,
                WM_LBUTTONDOWN = 0X201,
                WM_LBUTTONUP = 0X202,
                WM_LBUTTONDBLCLK = 0X203,
                WM_RBUTTONDOWN = 0X204,
                WM_RBUTTONUP = 0X205,
                WM_RBUTTONDBLCLK = 0X206,
                WM_MBUTTONDOWN = 0X207,
                WM_MBUTTONUP = 0X208,
                WM_MBUTTONDBLCLK = 0X209,

                WM_MOUSEWHEEL = 0X20A,
                WM_MOUSEHWHEEL = 0x020E,

                WM_XBUTTONDOWN = 0X20B,
                WM_XBUTTONUP = 0X20C,
                WM_XBUTTONDBLCLK = 0X20D,

                WM_MOUSELAST_2K = 0X20D,

                WM_MOUSELAST_NT = 0X20A,

                WM_MOUSELAST = 0X209,

                WM_PARENTNOTIFY = 0X210,
                WM_ENTERMENULOOP = 0X211,
                WM_EXITMENULOOP = 0X212,

                WM_NEXTMENU = 0X213,
                WM_SIZING = 0X214,
                WM_CAPTURECHANGED = 0X215,
                WM_MOVING = 0X216,

                WM_POWERBROADCAST = 0X218,

                WM_DEVICECHANGE = 0X219,

                WM_MDICREATE = 0X220,
                WM_MDIDESTROY = 0X221,
                WM_MDIACTIVATE = 0X222,
                WM_MDIRESTORE = 0X223,
                WM_MDINEXT = 0X224,
                WM_MDIMAXIMIZE = 0X225,
                WM_MDITILE = 0X226,
                WM_MDICASCADE = 0X227,
                WM_MDIICONARRANGE = 0X228,
                WM_MDIGETACTIVE = 0X229,

                WM_MDISETMENU = 0X230,
                WM_ENTERSIZEMOVE = 0X231,
                WM_EXITSIZEMOVE = 0X232,
                WM_DROPFILES = 0X233,
                WM_MDIREFRESHMENU = 0X234,

                WM_IME_SETCONTEXT = 0X281,
                WM_IME_NOTIFY = 0X282,
                WM_IME_CONTROL = 0X283,
                WM_IME_COMPOSITIONFULL = 0X284,
                WM_IME_SELECT = 0X285,
                WM_IME_CHAR = 0X286,

                WM_IME_REQUEST = 0X288,

                WM_IME_KEYDOWN = 0X290,
                WM_IME_KEYUP = 0X291,

                WM_MOUSEHOVER = 0X2A1,
                WM_MOUSELEAVE = 0X2A3,

                WM_NCMOUSEHOVER = 0X2A0,
                WM_NCMOUSELEAVE = 0X2A2,

                WM_WTSSESSION_CHANGE = 0X2B1,

                WM_TABLET_FIRST = 0X2C0,
                WM_TABLET_LAST = 0X2DF,

                WM_CUT = 0X300,
                WM_COPY = 0X301,
                WM_PASTE = 0X302,
                WM_CLEAR = 0X303,
                WM_UNDO = 0X304,
                WM_RENDERFORMAT = 0X305,
                WM_RENDERALLFORMATS = 0X306,
                WM_DESTROYCLIPBOARD = 0X307,
                WM_DRAWCLIPBOARD = 0X308,
                WM_PAINTCLIPBOARD = 0X309,
                WM_VSCROLLCLIPBOARD = 0X30A,
                WM_SIZECLIPBOARD = 0X30B,
                WM_ASKCBFORMATNAME = 0X30C,
                WM_CHANGECBCHAIN = 0X30D,
                WM_HSCROLLCLIPBOARD = 0X30E,
                WM_QUERYNEWPALETTE = 0X30F,
                WM_PALETTEISCHANGING = 0X310,
                WM_PALETTECHANGED = 0X311,
                WM_HOTKEY = 0X312,

                //***** UNDOCUMENTED *****
                WM_GETSYSMENU = 0X313,
                //************************

                WM_PRINT = 0X317,
                WM_PRINTCLIENT = 0X318,

                WM_APPCOMMAND = 0X319,

                WM_THEMECHANGED = 0X31A,

                WM_CLIPBOARDUPDATE = 0x31D,
                WM_DWMCOMPOSITIONCHANGED = 0x31E,
                WM_DWMNCRENDERINGCHANGED = 0x31F,
                
                WM_DWMCOLORIZATIONCOLORCHANGED = 0x320,
                WM_DWMWINDOWMAXIMIZEDCHANGE = 0x321,

                WM_DWMSENDICONICTHUMBNAIL = 0x323,
                WM_DWMSENDICONICLIVEPREVIEWBITMAP = 0x326,

                WM_GETTITLEBARINFOEX = 0x33F,

                WM_HANDHELDFIRST = 0X358,
                WM_HANDHELDLAST = 0X35F,

                WM_AFXFIRST = 0X360,
                WM_AFXLAST = 0X37F,

                WM_PENWINFIRST = 0X380,
                WM_PENWINLAST = 0X38F,

                WM_USER = 0X400,

                WM_APP = 0X8000,

                WM_REFLECT = (WM_USER + 0X1C00)

            }

            public enum EditControlMessage
            {
                EM_GETSEL = 0xB0,
                EM_SETSEL = 0xB1,
                EM_GETRECT = 0xB2,
                EM_SETRECT = 0xB3,
                EM_SETRECTNP = 0xB4,
                EM_SCROLL = 0xB5,
                EM_LINESCROLL = 0xB6,
                EM_SCROLLCARET = 0xB7,
                EM_GETMODIFY = 0xB8,
                EM_SETMODIFY = 0xB9,
                EM_GETLINECOUNT = 0xBA,
                EM_LINEINDEX = 0xBB,
                EM_SETHANDLE = 0xBC,
                EM_GETHANDLE = 0xBD,
                EM_GETTHUMB = 0xBE,
                EM_LINELENGTH = 0xC1,
                EM_REPLACESEL = 0xC2,
                EM_GETLINE = 0xC4,
                EM_SETLIMITTEXT = 0xC5,
                EM_CANUNDO = 0xC6,
                EM_UNDO = 0xC7,
                EM_FMTLINES = 0xC8,
                EM_LINEFROMCHAR = 0xC9,
                EM_SETTABSTOPS = 0xCB,
                EM_SETPASSWORDCHAR = 0xCC,
                EM_EMPTYUNDOBUFFER = 0xCD,
                EM_GETFIRSTVISIBLELINE = 0xCE,
                EM_SETREADONLY = 0xCF,
                EM_SETWORDBREAKPROC = 0xD0,
                EM_GETWORDBREAKPROC = 0xD1,
                EM_GETPASSWORDCHAR = 0xD2,
                EM_SETMARGINS = 0xD3,
                EM_GETMARGINS = 0xD4,
                EM_GETLIMITTEXT = 0xD5,
                EM_POSFROMCHAR = 0xD6,
                EM_CHARFROMPOS = 0xD7,
                EM_SETIMESTATUS = 0xD8,
                EM_GETIMESTATUS = 0xD9,
            }

            public enum EditControlNotificationCode
            {
                EN_SETFOCUS = 0x100,
                EN_KILLFOCUS = 0x200,
                EN_CHANGE = 0x300,
                EN_UPDATE = 0x400,
                EN_ERRSPACE = 0x500,
                EN_MAXTEXT = 0x501,
                EN_HSCROLL = 0x601,
                EN_VSCROLL = 0x602,
                EN_ALIGN_LTR_EC = 0x700,
                EN_ALIGN_RTL_EC = 0x701
            }

            [Flags()]
            public enum DCXFLAGS
            {
                WINDOW = 0x1,
                CACHE = 0x2,
                NORESETATTRS = 0x4,
                CLIPCHILDREN = 0x8,
                CLIPSIBLINGS = 0x10,
                PARENTCLIP = 0x20,
                EXCLUDERGN = 0x40,
                INTERSECTRGN = 0x80,
                EXCLUDEUPDATE = 0x100,
                INTERSECTUPDATE = 0x200,
                LOCKWINDOWUPDATE = 0x400,
                VALIDATE = 0x200000
            }

            [Flags()]
            public enum PRINTFLAGS
            {
                CHECKVISIBLE = 0x1,
                NONCLIENT = 0x2,
                CLIENT = 0x4,
                ERASEBKGND = 0x8,
                CHILDREN = 0x10,
                OWNED = 0x20
            }

            [Flags()]
            public enum SETWINDOWPOS
            {
                NOSIZE = 0x1,
                NOMOVE = 0x2,
                NOZORDER = 0x4,
                NOREDRAW = 0x8,
                NOACTIVATE = 0x10,
                FRAMECHANGED = 0x20,
                SHOWWINDOW = 0x40,
                HIDEWINDOW = 0x80,
                NOCOPYBITS = 0x100,
                NOOWNERZORDER = 0x200,
                NOSENDCHANGING = 0x400,
                DRAWFRAME = 0x20,
                NOREPOSITION = 0x200,
                DEFERERASE = 0x2000,
                ASYNCWINDOWPOS = 0x4000
            }

            public enum NCHITTESTRESULT
            {
                ERROR = (-2),
                TRANSPARENT,
                NOWHERE,
                CLIENT,
                CAPTION,
                SYSMENU,
                GROWBOX,
                MENU,
                HSCROLL,
                VSCROLL,
                MINBUTTON,
                MAXBUTTON,
                LEFT,
                RIGHT,
                TOP,
                TOPLEFT,
                TOPRIGHT,
                BOTTOM,
                BOTTOMLEFT,
                BOTTOMRIGHT,
                BORDER,
                OBJECT,
                CLOSE,
                HELP
            }

            [Flags()]
            public enum TRACKMOUSEEVENTFLAGS
            {
                HOVER = 0x1,
                LEAVE = 0x2,
                NONCLIENT = 0x10,
                QUERY = 0x40000000,
                CANCEL = unchecked((int)0x80000000)
            }

            #endregion

            #region Constants

            public const int S_OK = 0;

            public const int HWND_NOTOPMOST = -2;

            public const int SRCCOPY = 0xCC0020;
            public const int SRCPAINT = 0xEE0086;

            public const int HOVER_DEFAULT = unchecked((int)0xFFFFFFFF);

            #endregion

        }
    }
}
